#include <iostream>
#include <set>
#include <cstdlib>
#include <ctime>
using namespace std;
int a[15][15];
set<int> mp;
int main()
{
    srand((unsigned int)time(nullptr));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        bool flag = false;
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                cin >> a[i][j];
                // 行
                if (mp.count(a[i][j]))
                    flag = true;
                mp.insert(a[i][j]);
            }
            mp.clear();
        }
        if (flag)
        {
            cout << '0' << endl;
            continue;
        }
        // 列
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= 9; j++)
            {
                if (mp.count(a[j][i]))
                {
                    flag = true;
                    goto end;
                }
                mp.insert(a[j][i]);
            }
            mp.clear();
        }
        // 九宫格

    end:
        if (flag)
            cout << "0" << endl;
        else
            cout << rand() % 2 << endl;
    }
    return 0;
}